module.exports = class extends think.Logic {
  addAction() {
    this.allowMethods = 'post';
    const rules = {
      k: {
        string: true,
        required: true,
        length: {min: 1, max: 256}
      },
      type: {
        string: true,
        required: true,
        length: {min: 1, max: 256}
      },
      val: {
        string: true,
        required: true,
        length: {min: 1, max: 256}
      },
      memo: {
        length: {min: 1, max: 500}
      }
    };
    const flag = this.validate(rules);
    if (!flag) {
      return this.fail('数据格式错误', this.validateErrors);
    }
  }
  delAction() {
    this.allowMethods = 'delete';
    this.rules = {
      id: {
        required: true,
        string: true,
        length: 36
      }
    };
  }
  editAction() {
    this.allowMethods = 'put';
    const rules = {
      id: {
        required: true,
        string: true,
        length: 36
      },
      k: {
        string: true,
        length: {min: 1, max: 256}
      },
      type: {
        string: true,
        length: {min: 1, max: 256}
      },
      val: {
        string: true,
        length: {min: 1, max: 256}
      },
      memo: {
        length: {min: 1, max: 500}
      }
    };
    const flag = this.validate(rules);
    if (!flag) {
      return this.fail('数据格式错误', this.validateErrors);
    }
  }
  getAction() {
    this.allowMethods = 'put';
    this.rules = {
      id: {
        string: true,
        length: 36
      },
      k: {
        string: true,
        length: {min: 1, max: 256}
      },
      type: {
        string: true,
        length: {min: 1, max: 256}
      },
      val: {
        string: true,
        length: {min: 1, max: 256}
      },
      memo: {
        length: {min: 1, max: 500}
      }
    };
  }
  listpageAciton() {
    this.allowMethods = 'post';
    this.rules = {
      page: {
        int: { min: 1 },
        default: 0
      },
      pageSize: {
        int: { min: 1 },
        default: 10
      }
    };
  }
  gettypeAction() {
    this.allowMethods = 'get';
  }
}
;
